package com.cy.store.controller;

import com.cy.store.domain.District;
import com.cy.store.service.IDistrictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.Mapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Administrator
 * @version 1.0
 * @description: TODO
 * @date 2025/2/24 19:15
 */
@RestController
@RequestMapping("districts")
public class DistrictController extends BaseController {
    @Autowired
    private IDistrictService districtService;
    /**
     * 请求路径蛇父路径相同时用@RequestMapping（{“/”,","}），表示
     * districts后面跟着/或者什么都不跟都会进入这个方法
     * 点进去RequestMapping注解发现参数类型是一个String[]，
     * 并且传入一个路径时默认有{},传入一个以上路径时需要添加{}
     */
    @RequestMapping({"/",""})
    public JsonResult<List<District>> getByParent(String parent){
        //调用业务层方法获取数据
        List<District> list = districtService.getByParent(parent);
        //将数据响应给客户端
        return new JsonResult<>(OK,list);
    }
}
